﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace ManifestManaged.ViewModels
{
    public class SumViewModel : INotifyPropertyChanged
    {

        public ManifestCOM.interop.RegFreeCom model { get; set; }

        public void Setup()
        {
            model = new ManifestCOM.interop.RegFreeCom();
            model.onSumAsyncDone += model_onSumAsyncDone;
        }

        public event PropertyChangedEventHandler PropertyChanged;

        // This method is called by the Set accessor of each property. 
        // The CallerMemberName attribute that is applied to the optional propertyName 
        // parameter causes the property name of the caller to be substituted as an argument. 
        private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        private int a = 10;
        public int A
        {
            get
            {
                return this.a;
            }

            set
            {
                this.a = value;
                NotifyPropertyChanged();
            }
        }

        private int b = 5;
        public int B
        {
            get
            {
                return this.b;
            }

            set
            {
                this.b = value;
                NotifyPropertyChanged();
            }
        }

        private int result = 0;
        public int Result
        {
            get
            {
                return this.result;
            }

            set
            {
                this.result = value;
                NotifyPropertyChanged();
            }
        }

        private int resultAsync = 0;
        public int ResultAsync
        {
            get
            {
                return this.resultAsync;
            }

            set
            {
                this.resultAsync = value;
                NotifyPropertyChanged();
            }
        }


        internal void Sum()
        {
            Result = model.Sum(A, B);
        }

        internal void SumAsync()
        {
            model.SumAsync(A, B);
        }

        void model_onSumAsyncDone(int a, int b, int result)
        {
            ResultAsync = result;
        }


    }

}
